<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="mengxiangzhong">
		<title>上传卡内消费记录</title>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script language="javascript" src="../script/common_stat.js" type="text/javascript"></script>
		<script type="text/javascript">
			//初始化页面信息
			var Page;
			function initPageElements(){
				
				Page.options = {disAppInfo:true,grayStatus:true,disBalance:false,disLoyalty:false,disPersonInfo:true};
				Page.sql = 'upload_tx_list';
				Page.checkAuthority = function(result){
					if (Page.raw.card.grayFund || Page.raw.card.grayPoint)
						showWarning("卡片被灰锁，虽然可以继续进行充值，但是建议尽快进行解灰操作。");
					return true;
				}
			}
	
			function uploadTxData(){
				var operForm = $('operationForm')
				if (!CardMgnt.checkCardAsn(Page.raw.card.asn))
					return;
				if (!Page.raw.card.pin)
					Page.raw.card.pin = CardMgnt.inputCardPin(); 
				if (!Page.raw.card.pin)
					return;
					
				var trades;
				var lyTrades
				try{
					trades = getTrans(Page.raw.card.pin);			//资金消费记录
					lyTrades = getLoyaltyTrans(Page.raw.card.pin)	//积分消费记录
					if(!trades && !lyTrades)
						showWarning('卡中没有交易记录')
					for(var i=0; i<lyTrades.length;i++){
						trades.push(lyTrades[i])
					}
				}catch(e){
					showError(e.description);
					return;
				}
				
				try{
					var result = DWR.syncCall("cardTxService.uploadConsumeRecord",
									 Page.raw.card.asn,
									 trades
						 		)
					if(result == null){
						showInformation('没有新交易入帐');
					}else{
						showInformation('上传成功');
						showUploadedTrades(result);
					}
				}catch(e){
					showError(e.description)
				}
			}
			
			function showUploadedTrades(result){
 				if (!Page.qt)
					Page.qt = new QueryTable(Page.sql,Page.searchForm,"datalist",[],{exportable:true});
				Page.qt.paramFunc = function(){
					return {uploadIdList:result};
				}
				Page.qt.showTable();
 				switchPage('printSheetDiv');
			}
		</script>
	</head>
	<body onload="TX.Trade.init()">
		<!--页面导航-->
		<div class="nav"><div id="nav">&nbsp;</div></div>
		
		<div id="operationFormDiv">
			<form id="operationForm" name="operationForm">
				<div class="form">
					<div class="formTitle">卡片信息</div>
					<span id="readonlyInfo"></span>
						<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label8">
						<tr>
							
						</tr>
					</table>
				</div>
				<p>
					<button onclick="TX.Trade.ReadCard()">读 卡</button>
					<button name="operation" onclick="uploadTxData();">上 传</button>
				</p>
			</form>
		</div>
		
		<div id="printSheetDiv" style="display:none;">
			<div id="datalist"></div>
			<p>
				<button onclick="WebPrint.preview('datalist')">打印预览</button>
				<button onclick="WebPrint.print('datalist')">打印</button>
				<button onclick="TX.Trade.goFirstPage()">返 回</button>
			</p>
		</div>
	</body>
</html>